#pragma once

#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif

#include <d3d9.h>

class CTimer
{
public:
	inline CTimer(void) { dt = -1 ; }
public:
	inline virtual ~CTimer(void) { } 

	inline void start() 
	{ 
		cntsPerSec = 0;
		QueryPerformanceFrequency((LARGE_INTEGER*)&cntsPerSec) ;
		secsPerCnt = 1.0f / (float)cntsPerSec ;
		prevTimeStamp = 0;
		QueryPerformanceCounter((LARGE_INTEGER*)&prevTimeStamp);
	}

	inline void stop()
	{
		currTimeStamp = 0;
		QueryPerformanceCounter((LARGE_INTEGER*)&currTimeStamp);
		dt = (currTimeStamp - prevTimeStamp)*secsPerCnt;
		prevTimeStamp = currTimeStamp ;
	}

	inline float elapsed()
	{ return dt ; }

private:
	__int64 currTimeStamp , prevTimeStamp , cntsPerSec ;
	float secsPerCnt , dt ;
};